package com.design.fitment.fragment;



import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.RadioGroup;

import com.design.fitment.R;
import com.design.fitment.fragment.FragmentGalleryHome;
import com.design.fitment.fragment.FragmentGalleryPublic;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;


public class GalleryActivity extends Fragment {





    @ViewInject(R.id.radiogrop_gallery)
    RadioGroup radioGroup;


    FragmentGalleryHome fragmentGalleryHome;
    FragmentGalleryPublic fragmentGalleryPublic;



    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_gallery, null);
        ViewUtils.inject(this, view);




        iniView();

        return view;
    }

    private void iniView() {
        final android.support.v4.app.FragmentManager supportFragmentManager = getFragmentManager();

        fragmentGalleryHome = new FragmentGalleryHome();
        fragmentGalleryPublic = new FragmentGalleryPublic();





       android.support.v4.app.FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();

        fragmentTransaction.replace(R.id.fl_gallery,fragmentGalleryHome);
        fragmentTransaction.commit();

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        android.support.v4.app.FragmentTransaction  fragmentTransaction = supportFragmentManager.beginTransaction();
        switch (checkedId){
            case R.id.radioButton_home:
                fragmentTransaction.replace(R.id.fl_gallery, fragmentGalleryHome);
        fragmentTransaction.commit();break;
            case R.id.radioButton_work:
                fragmentTransaction.replace(R.id.fl_gallery, fragmentGalleryPublic);
        fragmentTransaction.commit();break;

        }
    }
});

    }


    class gridViewListener implements AdapterView.OnItemClickListener {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                long arg3) {

          //  Toast.makeText(GalleryActivity.this, "arg2 = " + arg2, Toast.LENGTH_LONG).show();
         //   System.out.println("arg2 = " + arg2); // 打印出点击的位置
        }
    }

}
